#pragma once
#include <iostream>
#include <ctime>
#include <cstring>

#define INF 0
#define DBG 1
#define ERR 2
#define LOG_LEVEL -1

#define LOG(level, format, ...) do{\
    if(level < LOG_LEVEL) break;\
    time_t t = time(nullptr);\
    struct tm *tm = localtime(&t);\
    char log_buf[64];\
    strftime(log_buf, sizeof(log_buf) - 1, "%Y-%m-%d %H:%M:%S", tm);\
    fprintf(stdout, "[%p %s %s:%d] " format "\n", (void*)pthread_self(), log_buf, __FILE__, __LINE__, ##__VA_ARGS__);\
}while(0)

#define LOG_INFO(format, ...) LOG(INF, format, ##__VA_ARGS__)
#define LOG_DEBUG(format, ...) LOG(DBG, format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) LOG(ERR, format, ##__VA_ARGS__)